package com.deke.order.service.Impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deke.entity.ShoucangTeacher;
import com.deke.order.dao.ShoucangTeacherDao;
import com.deke.order.service.QianShouCangTeacherService;
import com.deke.order.vo.ShouCangTeacherVo;
import com.deke.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author ：Username 刘亦辰（59372312@qq.com）
 * @date ：Created in 2022/12/30 17:04
 * @description：
 * @modified By：
 * @version:
 **/
@Service
public class QianShouCangTeacherServiceImpl implements QianShouCangTeacherService {
    @Autowired
    private ShoucangTeacherDao shoucangTeacherDao;


    /**
     * @create by: Username 刘亦辰 
     * @description: 根据会员id查询关注的讲师 
     * @create time: 2022/12/30 17:14
     * @param null
     * @return :  
     **/
    public Result findAttentionTeacher(ShouCangTeacherVo shouCangTeacherVo){
        Integer guanZhuStatus= 0;
        QueryWrapper<ShoucangTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("member_id",shouCangTeacherVo.getMemberid());
        wrapper.eq("teacher_id",shouCangTeacherVo.getTeacherid());
        ShoucangTeacher shoucangTeacher = shoucangTeacherDao.selectOne(wrapper);
        if (ObjectUtil.isNotEmpty(shoucangTeacher)){
            guanZhuStatus =1;
            return new Result(2000,"已关注",guanZhuStatus);
        }
        return new Result(2000,"未关注",guanZhuStatus);
    }


    /**
     * @create by: Username 刘亦辰 
     * @description: 关注老师 
     * @create time: 2022/12/30 17:46
     * @param null
     * @return :  
     **/
    @Override
    public Result addAttentionTeacher(ShouCangTeacherVo shouCangTeacherVo) {
        ShoucangTeacher shoucangTeacher = new ShoucangTeacher();
        shoucangTeacher.setMemberId(shouCangTeacherVo.getMemberid());
        shoucangTeacher.setTeacherId(shouCangTeacherVo.getTeacherid());
        int insert = shoucangTeacherDao.insert(shoucangTeacher);
        if (ObjectUtil.isNotEmpty(insert)){
            return new Result(2000,"关注成功");
        }
        return new Result(0000,"关注失败");
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 取关老师 
     * @create time: 2022/12/30 17:47
     * @param null
     * @return :  
     **/
    @Override
    public Result deleteAttentionTeacher(ShouCangTeacherVo shouCangTeacherVo) {
        QueryWrapper<ShoucangTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",shouCangTeacherVo.getTeacherid());
        wrapper.eq("member_id",shouCangTeacherVo.getMemberid());
        int delete = shoucangTeacherDao.delete(wrapper);
        if (ObjectUtil.isNotEmpty(delete)){
            return new Result(2000,"取关成功" );
        }
        return new Result(0000,"取关失败");
    }


}